<template>
  <el-input v-model="searchText" placeholder="请输入企业id或昵称" style="width: 200px; margin-right: 10px" />
  <el-button @click="handleClick" type="primary">
    <el-icon style="vertical-align: middle">
      <Search />
    </el-icon>
    <span style="vertical-align: middle"> Search </span>
  </el-button>

  <el-table :data="tableData" style="width: 100%">
    <el-table-column fixed prop="companyId" label="企业ID" width="200" />
    <el-table-column prop="name" label="企业昵称" width="200" />
    <el-table-column prop="status" label="企业融资" width="200" />
    <el-table-column prop="size" label="企业规模" width="200" />
    <el-table-column prop="companyType" label="企业类型" width="200" />
    <el-table-column fixed="right" label="Operations" min-width="200">
      <template #default="scope">
        <el-button @click="viewDetails(scope.row.companyId)" link type="primary" size="small">
          详细信息
        </el-button>
      </template>
    </el-table-column>
  </el-table>

  <el-pagination
      v-model:current-page="pageNum"
      v-model:page-size="pageSize"
      :page-sizes="[10, 15, 20, 25, 30]"
      layout="jumper, total, sizes, prev, pager, next"
      background
      :total="total"
      @size-change="onSizeChange"
      @current-change="onCurrentChange"
      style="margin-top: 20px;

              justify-content: flex-end" />

</template>

<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref } from 'vue'
import {getAllCompanyService} from "@/api/job.js";
import { ElMessage, ElMessageBox } from 'element-plus'
import {useRouter} from "vue-router";

//获取路由
const router = useRouter()
const tableData = ref([{
  companyId: '123456',
  name: '姓名',
  status: '出生日期',
  size: '学历',
  companyType: '联系电话',
}])

const pageNum = ref(1)
const total = ref(20)
const pageSize = ref(15)
const searchText = ref('')

const searchForm = ref({
  companyId: '',
  name: '',
  pageNum: pageNum.value,
  pageSize: pageSize.value
});

async function handleClick() {
  //判断输入的是否为数字
  if(searchText.value !== ''){
    if(!isNaN(searchText.value)) {
      searchForm.value.companyId = searchText.value
    }else {
      searchForm.value.name = searchText.value
    }
  }else {
    searchForm.value.companyId = ''
    searchForm.value.name = ''
  }
  searchForm.value.pageNum = pageNum.value
  searchForm.value.pageSize = pageSize.value
  console.log(searchForm.value)
  let result = await getAllCompanyService(searchForm.value);
  tableData.value = result.data.item;
  total.value = result.data.total
}

//首页搜索
async function GET_ALL_USERS(){
  searchForm.value.pageNum = pageNum.value
  searchForm.value.pageSize = pageSize.value
  let result = await getAllCompanyService(searchForm.value);
  tableData.value = result.data.item;
  total.value = result.data.total
}

GET_ALL_USERS()

const onSizeChange = (size) => {
  pageSize.value = size
  GET_ALL_USERS()
}

const onCurrentChange = (num) => {
  pageNum.value = num;
  GET_ALL_USERS()
}

const viewDetails = (companyId)=>{
  router.push(`/CompanyDetails/${companyId}`)
}
</script>

<style scoped>

</style>